//
//  MapFilterDropDownViews.swift
//  777Proj
//
//  Created by 陈宇 on 2017/5/9.
//  Copyright © 2017年 🐜. All rights reserved.
//

import UIKit
import RxSwift
import YNDropDownMenu

class StyleFilterDropDownView: YNDropDownView {

    @IBAction func smallAction(_ sender: UIButton) {
        changeMenu(title: "小户型", at: 0)
        hideMenu()
    }
    
    @IBAction func bigAction(_ sender: UIButton) {
        changeMenu(title: "大户型", at: 0)
        hideMenu()
    }
}

class PriceFilterDropDownView: YNDropDownView {
    
    var disposeBag = DisposeBag()
    
    @IBOutlet weak var tf_min: UITextField!
    @IBOutlet weak var tf_max: UITextField!
    @IBOutlet weak var btn_confirm: UIButton!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        configure()
    }
    
    override func dropDownViewClosed() {
        endEditing(true)
    }
    
    private func configure() {
        let min = tf_min.rx.text.orEmpty.map { (value) -> Float in
            return value.float ?? 0
        }.shareReplay(1)
        let max = tf_max.rx.text.orEmpty.map { (value) -> Float in
            return value.float ?? 0
        }.shareReplay(1)
        let enableValid = Observable.combineLatest(min, max) { $0 < $1 }.shareReplay(1)
        
        enableValid.bind(to: btn_confirm.rx.isEnabled).addDisposableTo(disposeBag)
        
    }
}

class SortFilterDropDownView: YNDropDownView {
    
    
}
